<template>
	<div class="modal fade" tabindex="-1" role="dialog">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
					<h4 class="modal-title">{{operationName}}教师</h4>
				</div>
				<div class="modal-body">
					<form class="form-horizontal">
						<div class="form-group">
							<label class="col-sm-2 control-label">教师名称</label>
							<div class="col-sm-10">
								<input class="form-control" v-model="teacher.name">
							</div>
						</div>
						
						<div class="form-group">
							<label class="col-sm-2 control-label">昵称</label>
							<div class="col-sm-10">
								<input class="form-control" v-model="teacher.nickname">
							</div>
						</div>						
						
						<div class="form-group">
							<label class="col-sm-2 control-label">头像</label>
							<div class="col-sm-10">					

								<file ref="file" text="上传头像" :afterUpload="afterUpload" :suffixs="suffixs"
									:uploadUrl="uploadUrl" :purpose="$global.constant.FILE_PURPOSE.teacher"></file>
								<div v-if="teacher.image" class="row">
									<img :src="teacher.image"  class="col-sm-4"/>
								</div>
							</div>
						</div>
						
						<div class="form-group">
							<label class="col-sm-2 control-label">职位</label>
							<div class="col-sm-10">
								<input class="form-control" v-model="teacher.position">
							</div>
						</div>
						
						<div class="form-group">
							<label class="col-sm-2 control-label">座右铭</label>
							<div class="col-sm-10">
								<input class="form-control" v-model="teacher.motto">
							</div>
						</div>
						
						<div class="form-group">
							<label class="col-sm-2 control-label">简介</label>
							<div class="col-sm-10">
								<!-- <input class="form-control" v-model="teacher.intro"> -->
								<textarea v-model="teacher.intro" rows="3" class="form-control"></textarea>
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
					<button type="button" class="btn btn-primary" @click="save">{{operationName}}</button>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal-dialog -->
	</div><!-- /.modal -->
</template>

<script>
import file from '@/views/components/bigFile'
export default{
	data() {
		return {
			suffixs: ['jpg', 'jpeg', 'png'],
			uploadUrl: process.env.VUE_APP_SERVER + 'file/admin/file/upload/image/teacher',
		}
	},
	props: {
		teacher: Object
	},
	components:{
		file
	},
	computed: {
		operationName() {
			return this.teacher.id ? "修改" : "新增"
		}
	},
	methods: {
		save() {
			if(!this.$global.validator.require(this.teacher.name, '名称')) return
			let url = process.env.VUE_APP_SERVER + 'business/admin/teacher/save'
			this.$axios.post(url, this.teacher)
				.then(res => {
					if(res.data.status === 1) {
						this.$toast(this.operationName + '教师成功', this.$global.toast.success)
						$('#save-modal').modal('hide')
						this.$parent.list(1)
					}else {
						this.$toast(res.data.msg, this.$global.toast.fail)
					}
				})
		},
		afterUpload(resp) {
			console.log(resp)
			this.teacher.image = resp.data.path
		}
	}
}	
</script>

<style>
</style>
